﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TyMES.Model.Record;


namespace TyMES.ViewModel.Record.SkipOperationsVMs
{
    public partial class SkipOperationsListVM : BasePagedListVM<SkipOperations_View, SkipOperationsSearcher>
    {

        protected override IEnumerable<IGridColumn<SkipOperations_View>> InitGridHeader()
        {
            return new List<GridColumn<SkipOperations_View>>{
                this.MakeGridHeader(x => x.Snnumber),
                this.MakeGridHeader(x => x.OperationCode),
                this.MakeGridHeader(x => x.OperationId),
                this.MakeGridHeader(x => x.OperationName),
                this.MakeGridHeader(x => x.OrderCode),
                this.MakeGridHeader(x => x.OrderId),
                this.MakeGridHeader(x => x.IsSkip),
                this.MakeGridHeader(x => x.AddTime),
                this.MakeGridHeader(x => x.EditTime),
                this.MakeGridHeader(x => x.LastOperationCode),
                this.MakeGridHeader(x => x.LineCode),
                this.MakeGridHeader(x => x.NextNode),
                this.MakeGridHeader(x => x.NextOperationCode),
                this.MakeGridHeader(x => x.NextOperationId),
                this.MakeGridHeader(x => x.ParentOperationCode),
                this.MakeGridHeader(x => x.ParentOperationId),
                this.MakeGridHeader(x => x.RouteName),
                this.MakeGridHeader(x => x.RouteNumber),
                this.MakeGridHeader(x => x.RouteVersion),
                this.MakeGridHeader(x => x.ScheduleNumber),
                this.MakeGridHeader(x => x.Sort),
                this.MakeGridHeader(x => x.IsValid),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SkipOperations_View> GetSearchQuery()
        {
            var query = DC.Set<SkipOperations>()
                .CheckContain(Searcher.Snnumber, x=>x.Snnumber)
                .CheckContain(Searcher.OperationCode, x=>x.OperationCode)
                .CheckContain(Searcher.OperationId, x=>x.OperationId)
                .CheckContain(Searcher.OperationName, x=>x.OperationName)
                .CheckContain(Searcher.OrderCode, x=>x.OrderCode)
                .CheckContain(Searcher.OrderId, x=>x.OrderId)
                .CheckEqual(Searcher.IsSkip, x=>x.IsSkip)
                .CheckBetween(Searcher.AddTime?.GetStartTime(), Searcher.AddTime?.GetEndTime(), x => x.AddTime, includeMax: false)
                .CheckBetween(Searcher.EditTime?.GetStartTime(), Searcher.EditTime?.GetEndTime(), x => x.EditTime, includeMax: false)
                .CheckContain(Searcher.LastOperationCode, x=>x.LastOperationCode)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckContain(Searcher.NextNode, x=>x.NextNode)
                .CheckContain(Searcher.NextOperationCode, x=>x.NextOperationCode)
                .CheckContain(Searcher.NextOperationId, x=>x.NextOperationId)
                .CheckContain(Searcher.ParentOperationCode, x=>x.ParentOperationCode)
                .CheckContain(Searcher.ParentOperationId, x=>x.ParentOperationId)
                .CheckContain(Searcher.RouteName, x=>x.RouteName)
                .CheckContain(Searcher.RouteNumber, x=>x.RouteNumber)
                .CheckContain(Searcher.RouteVersion, x=>x.RouteVersion)
                .CheckContain(Searcher.ScheduleNumber, x=>x.ScheduleNumber)
                .CheckContain(Searcher.Sort, x=>x.Sort)
                .CheckEqual(Searcher.IsValid, x=>x.IsValid)
                .Select(x => new SkipOperations_View
                {
				    ID = x.ID,
                    Snnumber = x.Snnumber,
                    OperationCode = x.OperationCode,
                    OperationId = x.OperationId,
                    OperationName = x.OperationName,
                    OrderCode = x.OrderCode,
                    OrderId = x.OrderId,
                    IsSkip = x.IsSkip,
                    AddTime = x.AddTime,
                    EditTime = x.EditTime,
                    LastOperationCode = x.LastOperationCode,
                    LineCode = x.LineCode,
                    NextNode = x.NextNode,
                    NextOperationCode = x.NextOperationCode,
                    NextOperationId = x.NextOperationId,
                    ParentOperationCode = x.ParentOperationCode,
                    ParentOperationId = x.ParentOperationId,
                    RouteName = x.RouteName,
                    RouteNumber = x.RouteNumber,
                    RouteVersion = x.RouteVersion,
                    ScheduleNumber = x.ScheduleNumber,
                    Sort = x.Sort,
                    IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SkipOperations_View : SkipOperations{

    }
}
